package src.main.java.org.netWorkProgram.UDP.demo2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    public static void main(String[] args) throws Exception {
        //1.创建服务端对象,要注册端口
        DatagramSocket socket = new DatagramSocket(6666);
        //2.创建一个数据包对象，接收数据
        byte[] buffer = new byte[1024 * 64];
        DatagramPacket packet = new DatagramPacket(buffer,buffer.length);

        while (true) {
            //3.正式使用数据包接收数据
            socket.receive(packet);
            //4.从字节数组中，把接收到的数据直接打印
            int length = packet.getLength();
            String s = new String(buffer,0,length);
            System.out.println(s);
        }
    }
}
